//
//  BCRecommendTableCell.m
//  BananaChat
//
//  Created by 于洪东 on 2019/11/1.
//  Copyright © 2019 香蕉. All rights reserved.
//

#import "BCRecommendTableCell.h"
#import "BCOnlineStateView.h"

@interface BCRecommendTableCell ()

@property (nonatomic,strong) UIImageView *iconImageView;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) BCOnlineStateView *onlineView;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *introLabel;
@property (nonatomic,strong) UILabel *ageLabel;
@property (nonatomic,strong) UIButton *videoButton;

@end


@implementation BCRecommendTableCell
#pragma mark - ♻️life cycle
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - 🔄overwrite

#pragma mark - 🚪public
-(void)fillCellWithModel:(BCRecommendVideoModel *)model{
    [self.iconImageView yy_setImageWithURL:[NSURL URLWithString:model.headPictureUrl] placeholder:nil];
    
    NSString *priceString = [NSString stringWithFormat:@"%@ 樱桃/分钟",model.servicePrice];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:priceString];
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12*ScaleX] range:NSMakeRange(priceString.length - 5, 5)];
    self.priceLabel.attributedText = attrString;
    
    self.nameLabel.text = model.nickname;
    self.introLabel.text = model.personalitySignature;
    if ([model.gender isEqualToString:@"女"]) {
        self.ageLabel.text = [NSString stringWithFormat:@"♀%@",model.age];
    }else{
        self.ageLabel.text = [NSString stringWithFormat:@"♂%@",model.age];
    }
    
}



#pragma mark - 🍐delegate

#pragma mark - ☎️notification

#pragma mark - 🎬event response
-(void)videoButtonClick:(UIButton *)sender{
    DEF_DEBUG(@"%s",__func__);
}

#pragma mark - 🔒private

#pragma mark - 🌲setupUI
-(void)setupUI{
    self.backgroundColor = NTBackGroundColor;
    
    [self addSubview:self.iconImageView];
    [self.iconImageView addSubview:self.priceLabel];
    [self.iconImageView addSubview:self.onlineView];
    [self.iconImageView addSubview:self.nameLabel];
    [self.iconImageView addSubview:self.ageLabel];
    [self.iconImageView addSubview:self.introLabel];
    [self.iconImageView addSubview:self.videoButton];
    
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(10*ScaleX);
        make.right.equalTo(self).offset(-10*ScaleX);
        make.bottom.equalTo(self);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.iconImageView).offset(10*ScaleX);
        make.height.mas_equalTo(20*ScaleX);
        make.width.mas_equalTo(100*ScaleX);
    }];
    
    [self.onlineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView).offset(10*ScaleX);
        make.right.equalTo(self.iconImageView).offset(-10*ScaleX);
        make.width.mas_equalTo(60*ScaleX);
        make.height.mas_equalTo(20*ScaleX);
    }];
    
    self.onlineView.states = BCOnlineStatesOnLine;
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView).offset(10*ScaleX);
        make.bottom.equalTo(self.introLabel.mas_top);
        make.height.mas_equalTo(30*ScaleX);
    }];
    
    [self.introLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView).offset(10*ScaleX);
        make.bottom.equalTo(self.iconImageView).offset(-5*ScaleX);
        make.right.equalTo(self.iconImageView).offset(-80*ScaleX);
        make.height.mas_equalTo(20*ScaleX);
    }];
    
    [self.videoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.iconImageView).offset(-10*ScaleX);
        make.width.height.mas_equalTo(44*ScaleX);
    }];
    
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
        make.height.mas_equalTo(16*ScaleX);
        make.width.mas_equalTo(40*ScaleX);
    }];
    
}

#pragma mark - ☸getter and setter

-(UIImageView *)iconImageView{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc]init];
        _iconImageView.backgroundColor = NTLightGrayColor;
        _iconImageView.layer.cornerRadius = 5;
        _iconImageView.clipsToBounds = YES;
        _iconImageView.userInteractionEnabled = YES;
    }
    return _iconImageView;
}

-(UILabel *)priceLabel{
    if (_priceLabel == nil) {
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.font = [UIFont systemFontOfSize:16*ScaleX];
        _priceLabel.textColor = [UIColor whiteColor];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        _priceLabel.layer.cornerRadius = 10*ScaleX;
        _priceLabel.clipsToBounds = YES;
        _priceLabel.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
    }
    return _priceLabel;
}

-(BCOnlineStateView *)onlineView{
    if (_onlineView == nil) {
        _onlineView = [[BCOnlineStateView alloc]init];
        _onlineView.layer.cornerRadius = 10*ScaleX;
    }
    return _onlineView;
}

-(UILabel *)nameLabel{
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18*ScaleX];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.text = @"磨人的小妖精";
    }
    return _nameLabel;
}

-(UILabel *)introLabel{
    if (_introLabel == nil) {
        _introLabel = [[UILabel alloc]init];
        _introLabel.font = [UIFont boldSystemFontOfSize:12*ScaleX];
        _introLabel.textColor = [UIColor whiteColor];
        _introLabel.textAlignment = NSTextAlignmentLeft;
        _introLabel.text = @"最高人气主播喜欢直接视频";
    }
    return _introLabel;
}

-(UIButton *)videoButton{
    if (_videoButton == nil) {
        _videoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _videoButton.backgroundColor = NTMainColor;
        [_videoButton addTarget:self action:@selector(videoButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _videoButton.layer.cornerRadius = 22*ScaleX;
        _videoButton.clipsToBounds = YES;
    }
    return _videoButton;
}

-(UILabel *)ageLabel{
    if (_ageLabel == nil) {
        _ageLabel = [[UILabel alloc]init];
        _ageLabel.font = [UIFont systemFontOfSize:12*ScaleX];
        _ageLabel.textColor = [UIColor whiteColor];
        _ageLabel.textAlignment = NSTextAlignmentCenter;
        _ageLabel.layer.cornerRadius = 8*ScaleX;
        _ageLabel.clipsToBounds = YES;
        _ageLabel.backgroundColor = NTMainColor;
    }
    return _ageLabel;
}












@end
